using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace UI
{
    public class UserNameItem : MonoBehaviour
    {
        private GameObject select;//选中
        private TextMeshProUGUI txt;//文本
        private UserData userData;
        private Button btn;
        private UserListPanel parent;

        private void Awake()
        {
            txt = transform.Find("用户").GetComponent<TextMeshProUGUI>();
            select = transform.Find("选中").gameObject;
            select.SetActive(false);
            btn = GetComponent<Button>();
            btn.onClick.AddListener(OnBtnNameItem);
        }

        public void Init(UserData userData, UserListPanel userPanel)
        {
            this.userData = userData;
            txt.text = userData.name;
            parent = userPanel;
        }

        void OnBtnNameItem()
        {
            parent.CurName = userData.name;
        }
        public void RefreSelect()
        {
            select.SetActive(userData.name == parent.CurName);
        }
    }

}
